package app.netant.book.mianhuatang;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;
/**
 * 
 * @author JiaJ
 *
 */
public class MianHuaTangDetail extends BaseDetail {

	public MianHuaTangDetail(String netSite) {
		super(netSite);
		this.preHref = "http://www.mianhuatang.la";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select(".main .txt_nav a");
		if(parts.size()>2){
			String title = parts.get(2).text();
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
		
		Elements parts1 = this.select(".main .txt_nav");
		
		if(parts1.size()>0){
			String text = parts1.get(0).text().trim();
			int idx = text.indexOf("作者：");
			
			//七叶重华txt下载（作者：古风卷）
			if(idx>0 && text.endsWith("）")){
				String writer = text.substring(idx+3,text.length()-1).trim();
				System.out.println("【Writer】:"+writer);
				this.entity.setNovelWriter(writer);
			}
		}
	}

	@Override
	public void analyseTags() {
		Elements parts = this.select(".main .txt_top .xiazai .txt_info .show_num ul li");
		for(int i=0;i<parts.size();i++){
			String tags = parts.get(i).text();
			int idx = tags.indexOf("：");
			if(idx>0){
				String tagName = tags.substring(0,idx).trim();
				String tagValue = tags.substring(idx+1).trim();
				System.out.println("【Tag】:"+tagName+"="+tagValue);
				this.entity.setTag(tagName, tagValue);
			}
		}
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select(".main .txt_top .xiazai .txt_info .show_num .intro p");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select(".main .txt_top .xiazai #down_txt_url .txt_down a");
		if(parts.size()>0){
			String href = parts.get(0).attr("href");
			System.out.println("【Href】:"+href);
			this.entity.setDownPath(href);
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select(".main .txt_nav a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		MianHuaTangDetail detail = new MianHuaTangDetail("http://www.mianhuatang.la/down/txt70072.html");
		detail.test();
	}



}
